package com.leetcode.题库;

import com.leetcode.common.model.ListNode;

/**
 * @author 覃国强
 * @date 2022-03-23 18:31
 */
public class 题库_0206_反转链表 {


  static
  class Solution {
    public ListNode reverseList(ListNode head) {

      if (head == null || head.next == null) {
        return head;
      }

      ListNode prev = null;
      ListNode node = head;
      ListNode next;

      while (node != null) {
        next = node.next;
        node.next = prev;
        prev = node;
        node = next;
      }

      return prev;
    }
  }

}
